<?php namespace app\admin\controller;

use houdunwang\route\Controller;
use system\model\Article as articleModel;
use system\model\Category as categoryModel ;

class Article extends Common {
    //动作
    public function __construct()
    {
         $this->auth();
    }

//    文章管理
    public function index(articleModel $article){
//        数据分页+
        $field=$article->paginate(v('config.article_num'));
        //此处书写代码...
//        return view('',$field);  //错误代码
        return view('',compact('field'));
//
    }
//    文章添加与删除
    public function post(articleModel $article,categoryModel $category){
        
        $art_id=Request::get('art_id',0,'intval');
//        p($art_id);die;
        if(IS_POST){
            
            if($art_id){
//                编辑
                $article = articleModel::find($art_id);
            }
//            添加
//            p(Request::post());die;
            $article->save(Request::post());
            return message('操作成功','index','success');
        }
        
        if($art_id){
//            编辑
            $oldData = articleModel::find($art_id);
//            p($oldData->toArray());
        }
//            栏目数据
            $cateData=$category->getAllCate();
//          p($cateData);die;
//        分配两个数据去页面
        return view('',compact('cateData','oldData'));
    }
//    删除
    public function del(articleModel $article){
//        抓id
        $art_id=Request::get('art_id',0,'intval');
//        寻找这条数据
        $model = articleModel::find($art_id);
//        删除
        $model->destory();
//        提示跳转
        return message('删除成功','index','success');
    }
}
